#include "DAFuncTools.h"
#include "qscreen.h"
#include <QIcon>
#include <QStyle>
#include <QApplication>
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
#include <QNetworkConfigurationManager>
#endif
DAFunTools::DAFunTools()
{

}

void DAFunTools::ToCenter(QWidget *parents)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
    QScreen *ScreenObj = parents->screen();
    QRect RectObj = ScreenObj->geometry();
    int win_wid = RectObj.width() - parents->width();
    int win_hig = RectObj.height() - parents->height();
    parents->move( win_wid  / 2, win_hig / 2.5);

#else
    parents->move (
                (QApplication::desktop()->width() - parents->width())/2,
                (QApplication::desktop()->height() - parents->height())/2
                );
#endif

}

void DAFunTools::ToRight(QWidget *parents)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
    QScreen *ScreenObj = parents->screen();
    parents->setGeometry(QStyle::alignedRect(
                        Qt::RightToLeft,
                        Qt::AlignVertical_Mask,
                        parents->size(),
                        ScreenObj->availableGeometry())
                         );
#else
    parents->move (
                (QApplication::desktop()->width() - parents->width()),
                (QApplication::desktop()->height() - parents->height())/2
                );
#endif
}

QIcon DAFunTools::StdIcon(int num)
{
    QStyle* style = QApplication::style();
    QIcon icon = style->standardIcon((QStyle::StandardPixmap)num);
//    QPixmap m_pic = icon.pixmap(icon.actualSize(QSize(LIco->width()-9,LIco->height()-5)));//size自行调整
    return icon;
}

bool DAFunTools::isNetWorkOnline()
{
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
    QNetworkConfigurationManager mgr;
    return mgr.isOnline();
#endif

}
